-
Notifications
You must be signed in to change notification settings - Fork 863
Add gen_ai.tool_definitions to completion hook #4181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add gen_ai.tool_definitions to completion hook #4181
Conversation
| return [asdict(dc) for dc in dataclass_list] | ||
| response: JsonEncodeable = [] | ||
| for data in data_list: | ||
| if isinstance(data, dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In what case will it be a dict ? Don't you always serialize the tool definitions to a sting ? And otherwise it's a dataclass ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tool definitions are serialized into dictionaries, and in a fallback to a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DylanRussell ping on this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it makes sense for it to be this way, I confused myself thinking the hashed tool definitions (which I think is always a string) would be passed to this..
But this function takes the tool definitions as they are on the attribute, and in that case it'll be a dict or fallback to a string: https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation-genai/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/generate_content.py#L237
|
|
||
|
|
||
| def is_tool_definitions_hashable( | ||
| tool_definitions: list[types.MessagePart] | None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is tool definitions of types.MessagePart and can you give an example of what you would pass here?
I think we should have a dedicated type for this that callers have to convert to before calling this API. The other types in this API are part of the semantic conventions
opentelemetry-python-contrib/util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py
Lines 46 to 50 in 93bea2d
| """Represents a tool call requested by the model | |
| This model is specified as part of semconv in `GenAI messages Python models - ToolCallRequestPart | |
| <https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/non-normative/models.ipynb>`__. | |
| """ |
Could we align with open-telemetry/semantic-conventions#3378?
Description
This PR adds
gen_ai.tool_definitionsto completion hook and configures exporting the attribute to GCS. Its configured the same way as system instructions, it's being hashed, since it might be large and often doesn't differ.Its a continuation of #4142, which added
gen_ai.tool_definitionstogen_ai.client.inference.operation.details.Please delete options that are not relevant.
New feature (non-breaking change which adds functionality)
How Has This Been Tested?
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.